/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package etf.pia.converters;

import etf.pia.controlers.ProfBean;
import etf.pia.entity.Predmet;
import etf.pia.entity.Zaposleni;
import static etf.pia.util.MyLogger.log;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedProperty;
import javax.faces.component.UIComponent;
import javax.faces.component.UISelectItems;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import org.primefaces.component.picklist.PickList;
import org.primefaces.component.selectonemenu.SelectOneMenu;
import org.primefaces.model.DualListModel;

/**
 *
 * @author Alejandro
 */
@FacesConverter(value = "courseConverter")
public class CourseConverter implements Converter {


    @Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
        log.info("get as object");
        log.info(arg2);
        log.info(arg1.getChildCount());
        ArrayList<Predmet> pList =((ArrayList<Predmet>)((UISelectItems)arg1.getChildren().get(0)).getValue());
        log.info(pList);
        String s = "";
        for (Predmet p : pList) {
            s = p.getNaziv() + " - " + p.getSifra();
            if (s.equals(arg2)) {
                return p;
            }
        }
        return null;
    }

    @Override
    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
        log.info("get as string " + arg2);
        log.info(arg1);
        String str = "";
        if (arg2 instanceof Predmet) {
            str = "" + ((Predmet) arg2).getNaziv() + " - " + ((Predmet) arg2).getSifra();
        }
        return str;
    }
}
